using System.Collections;
using System.Collections.Generic;

namespace VirtualDeveloper.Filters
{
    internal class RoundRobinEnumerator<T> : IEnumerator<T>
    {
        private readonly IEnumerator<T> enumerator;

        public RoundRobinEnumerator(IEnumerable<T> enumerable)
        {
            enumerator = enumerable.GetEnumerator();
        }

        public void Dispose()
        {
            enumerator.Dispose();
        }

        public bool MoveNext()
        {
            if (enumerator.MoveNext()) return true;

            enumerator.Reset();
            return enumerator.MoveNext();
        }

        public void Reset()
        {
            enumerator.Reset();
        }

        public T Current
        {
            get { return enumerator.Current; }
        }

        object IEnumerator.Current
        {
            get { return Current; }
        }
    }
}